<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="140px">
  
    <el-form-item label="申请人编号" prop="applyNo">
      <el-input v-model="dataForm.applyNo" placeholder="申请人编号"></el-input>
    </el-form-item>
    <el-form-item label="申请人姓名" prop="applyName">
      <el-input v-model="dataForm.applyName" placeholder="申请人姓名"></el-input>
    </el-form-item>
    <el-form-item label="申请人类别" prop="applyType">
    <el-radio v-model="dataForm.applyType" label="游客">游客</el-radio>
    <el-radio v-model="dataForm.applyType" label="学生">学生</el-radio>
    <el-radio v-model="dataForm.applyType" label="教师">教师</el-radio>
    </el-form-item>
    <el-form-item label="申请权限" prop="applyPrivilege">
      <!-- <el-radio v-model="dataForm.applyPrivilege" label="游客权限">游客只读权限</el-radio>
    <el-radio v-model="dataForm.applyPrivilege" label="学生权限">学生学习权限</el-radio>
    <el-radio v-model="dataForm.applyPrivilege" label="教师权限">教师管理权限</el-radio> -->
    <div>
    <el-radio-group v-model="dataForm.applyPrivilege">
      <el-radio-button v-model="dataForm.applyPrivilege" label="游客权限"></el-radio-button>
      <el-radio-button v-model="dataForm.applyPrivilege" label="学生权限"></el-radio-button>
      <el-radio-button v-model="dataForm.applyPrivilege" label="教师权限"></el-radio-button>
    </el-radio-group>
  </div>
    </el-form-item>
    <el-form-item label="申请原因" prop="applyReason">
      <el-input type="textarea"
  :rows="4"
  placeholder="请输入内容" v-model="dataForm.applyReason"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSave()">保存</el-button>
      <el-button type="danger" @click="dataFormSubmit()">提交</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          gmtCreate: '',
          createBy: '',
          gmtModified: '',
          lastModifiedBy: '',
          isDeleted: '',
          sortNo: '',
          version: '',
          applyNo: '',
          applyName: '',
          applyType: '',
          applyPrivilege: '',
          applyReason: '',
          applyStatus: ''
        },
        dataRule: {
          gmtCreate: [
            { required: true, message: '记录创建时间不能为空', trigger: 'blur' }
          ],
          createBy: [
            { required: true, message: '记录创建者不能为空', trigger: 'blur' }
          ],
          gmtModified: [
            { required: true, message: '记录更新时间不能为空', trigger: 'blur' }
          ],
          lastModifiedBy: [
            { required: true, message: '记录最后更新人不能为空', trigger: 'blur' }
          ],
          isDeleted: [
            { required: true, message: '是否删除(1删除,0未删除)不能为空', trigger: 'blur' }
          ],
          sortNo: [
            { required: true, message: '序号不能为空', trigger: 'blur' }
          ],
          version: [
            { required: true, message: '版本不能为空', trigger: 'blur' }
          ],
          applyNo: [
            { required: true, message: '申请人编号不能为空', trigger: 'blur' }
          ],
          applyName: [
            { required: true, message: '申请人姓名不能为空', trigger: 'blur' }
          ],
          applyType: [
            { required: true, message: '申请人类别不能为空', trigger: 'blur' }
          ],
          applyPrivilege: [
            { required: true, message: '申请权限不能为空', trigger: 'blur' }
          ],
          applyReason: [
            { required: true, message: '申请原因不能为空', trigger: 'blur' }
          ],
          applyStatus: [
            { required: true, message: '申请状态(01_申请中,02_已通过,03_已驳回)不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/authority/tidentifyapply/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.gmtCreate = data.tIdentifyApply.gmtCreate
                this.dataForm.createBy = data.tIdentifyApply.createBy
                this.dataForm.gmtModified = data.tIdentifyApply.gmtModified
                this.dataForm.lastModifiedBy = data.tIdentifyApply.lastModifiedBy
                this.dataForm.isDeleted = data.tIdentifyApply.isDeleted
                this.dataForm.sortNo = data.tIdentifyApply.sortNo
                this.dataForm.version = data.tIdentifyApply.version
                this.dataForm.applyNo = data.tIdentifyApply.applyNo
                this.dataForm.applyName = data.tIdentifyApply.applyName
                this.dataForm.applyType = data.tIdentifyApply.applyType
                this.dataForm.applyPrivilege = data.tIdentifyApply.applyPrivilege
                this.dataForm.applyReason = data.tIdentifyApply.applyReason
                this.dataForm.applyStatus = data.tIdentifyApply.applyStatus
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSave () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/authority/tidentifyapply/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'gmtCreate': this.dataForm.gmtCreate,
                'createBy': this.dataForm.createBy,
                'gmtModified': this.dataForm.gmtModified,
                'lastModifiedBy': this.dataForm.lastModifiedBy,
                'isDeleted': this.dataForm.isDeleted,
                'sortNo': this.dataForm.sortNo,
                'version': this.dataForm.version,
                'applyNo': this.dataForm.applyNo,
                'applyName': this.dataForm.applyName,
                'applyType': this.dataForm.applyType,
                'applyPrivilege': this.dataForm.applyPrivilege,
                'applyReason': this.dataForm.applyReason,
                'applyStatus': this.dataForm.applyStatus
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      },
      // 表单提交
     dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/authority/tidentifyapply/submit`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'gmtCreate': this.dataForm.gmtCreate,
                'createBy': this.dataForm.createBy,
                'gmtModified': this.dataForm.gmtModified,
                'lastModifiedBy': this.dataForm.lastModifiedBy,
                'isDeleted': this.dataForm.isDeleted,
                'sortNo': this.dataForm.sortNo,
                'version': this.dataForm.version,
                'applyNo': this.dataForm.applyNo,
                'applyName': this.dataForm.applyName,
                'applyType': this.dataForm.applyType,
                'applyPrivilege': this.dataForm.applyPrivilege,
                'applyReason': this.dataForm.applyReason,
                'applyStatus': this.dataForm.applyStatus
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
